<template>
    <div class="device-frame-list">
        <div class="device-frame-list-container flex-container">

            <div class="panel-list">
                <div class="item-panel">
                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">订单号:</div>
                            <div class="content">{{orderInfo.sn}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">下单用户:</div>
                            <div class="content">{{orderInfo.user_info.nickname}}</div>
                        </div>
                    </div>
                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">商品数量:</div>
                            <div class="content">{{orderInfo.amount}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">商品价格:</div>
                            <div class="content">{{orderInfo.goods_price | currencyFormat}}</div>
                        </div>
                    </div>
                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">运费:</div>
                            <div class="content">{{orderInfo.express_fee | currencyFormat}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">总价:</div>
                            <div class="content">{{orderInfo.charge | currencyFormat}}</div>
                        </div>
                    </div>

                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">订单状态:</div>
                            <div class="content">{{orderInfo.status_name}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">下单时间:</div>
                            <div class="content">{{orderInfo.create_time | timeFormat}}</div>
                        </div>
                    </div>

                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">发货时间:</div>
                            <div class="content">{{orderInfo.delivery_time | timeFormat}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">快递单号:</div>
                            <div class="content">{{orderInfo.order_ext.express_company + "/" + orderInfo.order_ext.express_no}}</div>
                        </div>
                    </div>

                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">支付时间:</div>
                            <div class="content">{{orderInfo.pay_time | timeFormat}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">签收时间:</div>
                            <div class="content">{{orderInfo.sign_time | timeFormat}}</div>
                        </div>
                    </div>

                    <div class="row-content">
                        <div class="row-item">
                            <div class="title">收货人:</div>
                            <div class="content">{{orderInfo.order_ext | receiveContact}}</div>
                        </div>
                        <div class="row-item">
                            <div class="title">收货地址:</div>
                            <div class="content">{{orderInfo.order_ext | receiveAddress}}</div>
                        </div>
                    </div>

                </div>
                <div class="clear-20"></div>
            </div>

            <div class="device-list-table">

                <el-table :data="orderInfo.order_info_list" border>

                    <el-table-column label="ID" prop="id" width="120"></el-table-column>
                    <el-table-column label="商品名称" prop="goods_name" min-width="180"></el-table-column>
                    <el-table-column label="商品规格" prop="goods_spec_name" min-width="180"></el-table-column>
                    <el-table-column label="数量">
                        <template slot-scope="scope">
                            {{scope.row.amount}}
                        </template>
                    </el-table-column>
                    <el-table-column label="价格">
                        <template slot-scope="scope">
                            {{scope.row.goods_price | currencyFormat}}
                        </template>
                    </el-table-column>
                    <el-table-column label="运费">
                        <template slot-scope="scope">
                            {{scope.row.express_fee | currencyFormat}}
                        </template>
                    </el-table-column>
                    <el-table-column label="总价">
                        <template slot-scope="scope">
                            {{scope.row.charge | currencyFormat}}
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <div class="flex-footer h-80">
                <div class="flex-footer-content">
                    <el-row>
                        <el-col :span="8" class="pt-6">

                            <el-button type="success" @click="deliveryBtn">发货</el-button>
                            <!--<el-button type="success" @click="handleAddUser">添加用户</el-button>-->
                        </el-col>
                        <el-col :span="16" class="text-right" v-if="total > 0">
                            &nbsp;
                        </el-col>
                    </el-row>
                </div>
            </div>
        </div>

        <!--编辑弹窗-->
        <el-dialog title="更新到指定账户" custom-class="edit-dialog" :visible.sync="editModalVisible">
            <el-form :label-position="'left'" label-width="110px" ref="userForm" :model="userForm">
                <el-form-item label="目标用户名" prop="target_user_id">

                </el-form-item>
                <el-form-item label="目标分组">

                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="success" @click="saveUser('userForm')">确认更新</el-button>
            </div>
        </el-dialog>


        <!--发货弹窗-->
        <el-dialog title="发货" custom-class="edit-dialog" width="500px" :visible.sync="deliveryModalVisible">
            <el-form :label-position="'left'" label-width="110px" ref="userForm" :model="deliveryForm">
                <el-form-item label="快递公司">
                    <el-input type="text" v-model="deliveryForm.expressCompany"></el-input>
                </el-form-item>
                <el-form-item label="快递单号">
                    <el-input type="text" v-model="deliveryForm.expressNo"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="success" @click="handleDelivery('deliveryForm')">确认发货</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/ecmascript-6">

    import Core from 'core/core'

    export default {
        data() {
            return {
                editModalVisible: false,
                deliveryModalVisible: false,
                userForm: {

                },
                deliveryForm: {
                    expressCompany: "",
                    expressNo: ""
                },
                orderInfo: {
                    user_info: {},
                    order_ext: {}
                },
                orderList: [],
                orderId: 0,

                // 分页配置
                currentPage: 1,
                total: 0,
                pageSize: 10,
            }
        },
        filters: {
            receiveContact: function(data) {
                return `${data.receive_name}/${data.receive_contact}`
            },
            receiveAddress: function (data) {
                return `${data.receive_province}/${data.receive_city}/${data.receive_county}/${data.receive_address}`
            }
        },
        mounted: function () {
            this.orderId = this.$route.query.order_id || 0;

            this._orderDetail()
        },

        methods: {
            _orderDetail() {
                Core.Api.Order.detail(this.orderId)
                    .then(res => {
                        this.orderInfo = res.order
                    })
                    .catch(err => {})
            },

            deliveryBtn() {
                this.deliveryModalVisible = true;
            },
            handleDelivery(formName) {
                Core.Api.Order.delivery(this.orderId,
                    this.deliveryForm.expressCompany,
                    this.deliveryForm.expressNo)
                    .then(res => {
                        this.$message.success("发货成功")
                        this.deliveryModalVisible = false;
                        this._orderDetail();
                    })
            }

        }
    }
</script>

<style scoped lang="scss">
    .device-frame-list {
        padding-top: 10px;
        height: 100%;
        .device-frame-list-container {
            height: 100%;
            .search-row {
                margin: 0;
                padding: 15px 30px;
                background: #fff;
                .el-form-item__label {
                    padding-right: 10px;
                    font-size: 12px;
                }
                .el-form-item__content {
                    .el-input {
                        width: 95px;
                    }
                }
            }

            .device-frame-list-table {
                box-flex: 1;
                -webkit-box-flex: 1;
                -moz-box-flex: 1;
                flex: 1;
                -webkit-flex: 1;
                overflow: auto;
            }
        }

        a {
            cursor: pointer;
        }

        .panel-list {
            background: #fff;
            .item-panel {
                .tab-content {
                    padding: 0 20px;
                }

                &:first-child {
                    .row-title {
                        border-top: none;
                    }
                }
                .row-title {
                    height: 50px;
                    padding: 0 30px;
                    overflow: hidden;
                    border-top: 1px solid rgb(240, 240, 246);

                    .title {
                        font-size: 14px;
                        line-height: 50px;
                        color: #03CC75;
                        font-weight: bold;
                    }
                }

                .row-content {
                    overflow: hidden;
                    background: #FBFBFC;
                    .row-item {
                        width: 50%;
                        float: left;
                        height: 40px;
                        padding-left: 30px;
                        line-height: 40px;
                        border-top: 1px solid rgb(240, 240, 246);

                        &:nth-child(2n) {
                            border-left: 1px solid rgb(240, 240, 246);
                        }

                        .title {
                            font-weight: bold;
                            font-size: 12px;
                            color: #A9A9B1;
                            float: left;
                            width: 155px;
                        }

                        .content {
                            font-size: 12px;
                            color: #4D4D4D;
                            font-weight: bold;
                            float: left;
                        }
                        .action {
                            float: right;
                            width: 50px;
                            height: 50px;
                        }
                    }
                }
            }
        }
        .btn-row {
            padding: 15px 0;
        }
        .pb-40 {
            padding-bottom: 40px;
        }

        .el-radio {
            margin-right: 20px;
        }
        .bg-white {
            background: white;
        }

    }
</style>
